﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Chapter09.View
{
    /// <summary>
    /// SimpleDocumentWindow.xaml 的交互逻辑
    /// </summary>
    public partial class TwoDocumentWindow : Window
    {
        private bool isDirty = false;

        public TwoDocumentWindow()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            isDirty = true;
            ApplicationCommands.Save.CanExecute(null, (IInputElement)sender);
        }

        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Save)
            {
                e.CanExecute = isDirty;
            }
        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Save)
            {
                MessageBox.Show(this, ((TextBox)e.Source).Text, "已保存");
                isDirty = false;
            }
        }
    }
}
